/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conf2;

import conf2.model.EActor;
import conf2.model.ETerritory;
import conf2.model.Move;
import conf2.model.WorldState;
import static conf2.model.EActor.*;

/**
 *
 * @author Administrator
 */
public class Battle {

    public enum Result {

        NO_RESULT,
        ATTACKER_WINS, DEFENDER_WINS, BOTH_DIE,
        ATTACKER_RETREATS, DEFENDER_RETREATS, BOTH_RETREAT
    }

    /**
     * Evaluate the move in the given state of the world, and tell us
     * whether the move should cause a Balrog-in-Moria-and-light-player-uses-tunnel-instakill or not.
     * @param move
     * @param ws
     * @return 
     */
    public static boolean triggersTunnelKill(Move move, WorldState ws) {
        ETerritory from = move.getFrom();
        ETerritory to = move.getTo();

        if (from == ETerritory.EREGION && to == ETerritory.FANGORN) {
            assert move.getAttacker().isLight();
            return (ws.isAlive(C_BALROG) && ws.whereIs(C_BALROG) == ETerritory.MORIA);
        }
        return false;
    }

    public static Result instantResolution(EActor attacker, EActor defender, WorldState state) {
        assert state.isAlive(attacker);
        assert state.isAlive(defender);

        if ((attacker == C_BOROMIR && defender != C_WARG) ||
                (defender == C_BOROMIR && attacker != C_WARG)) {
            return Result.BOTH_DIE;
        }

        if (attacker == C_LEGOLAS && (defender == C_F_NAZGUL || defender == V_F_NAZGUL)) {
            return Result.ATTACKER_WINS;
        }
        if (defender == C_LEGOLAS && (attacker == C_F_NAZGUL || attacker == V_F_NAZGUL)) {
            return Result.DEFENDER_WINS;
        }

        if (attacker == C_GIMLI && (defender == C_ORCS || defender == V_ORCS)) {
            return Result.ATTACKER_WINS;
        }
        if (defender == C_GIMLI && (attacker == C_ORCS || attacker == V_ORCS)) {
            return Result.DEFENDER_WINS;
        }

        if (attacker == C_MERRY && (defender == C_WITCHKING || defender == V_WITCHKING)) {
            return Result.ATTACKER_WINS;
        }
        if (defender == C_MERRY && (attacker == C_WITCHKING || attacker == V_WITCHKING)) {
            return Result.DEFENDER_WINS;
        }

        if ((attacker == C_GANDALF || attacker == V_GANDALF) && defender == V_SARUMAN) {
            return Result.DEFENDER_WINS;
        }
        if ((defender == C_GANDALF || defender == V_GANDALF) && attacker == V_SARUMAN) {
            return Result.ATTACKER_WINS;
        }


        return Result.NO_RESULT;

    }
}
